trigger deleteAudit on Audit__c (before delete,before update) {
    
    Profile p  = [select id from profile where name=: 'System Administrator' or name =: '系统管理员'];
    List<Audit__c> delList = new List<Audit__c>();
    if(system.trigger.isdelete){
     for (Audit__c cp : Trigger.old)
     {
         if((cp.Plan_Date__c <= datetime.now())&&(p.id != UserInfo.getProfileId())){
             cp.addError('该记录不能被删除!');
         }
     }
   }
   
   if(system.trigger.isupdate){
       for(audit__c t:trigger.new){
           try{
               t.UniqueId__c=''+t.Plan_Date__c.year()+t.Plan_Date__c.month()+t.Plan_Date__c.day()+userinfo.getUserId().substring(0,15)+string.valueof(t.In_Store_Visit__c).substring(0,15);
           }catch(exception e){
               delete t;
           }
          
       }
       
   }
   
}